package pl.edu.agh.ssm.monitor.visualization;

import pl.edu.agh.ssm.monitor.data.SessionConnection;
import pl.edu.agh.ssm.monitor.data.SessionNode;

public class CommandLineItemDisplayer implements GraphNodeDisplayer, GraphEdgeDisplayer {

	@Override
	public void displayEdgeItem(SessionConnection connection) {
		if(connection != null) {
			System.out.println("Connection: " + connection.getConnectionAddress().getHostAddress() +
					":" + connection.getConnectionPort());
			System.out.println("Media: " + connection.getMediaDesc().getMediaType() +
					", " + connection.getMediaDesc().getMediaName() + ", "
					+ connection.getMediaDesc().getMediaFreq() + "[Hz]");
			System.out.println("Sender: " + connection.getSender().getAddress().getHostAddress()
					+ ", Receiver: " + connection.getReceiver().getAddress().getHostAddress());
			
			System.out.println("Last report: " + connection.getLastReceiverReportTime() +
					", last rtp: " + connection.getLastRtpPacket());
			if(connection.getReceiverReport() != null) {
			System.out.println(connection.getReceiverReport().getJitter() + ", "
					+ connection.getReceiverReport().getLastPackageReceivedStamp() + ", "
					+ connection.getReceiverReport().getLastSRRecvNTPTimeStamp());
			System.out.println(connection.getReceiverReport().getPackagesLostFraction() + ", "
					+ connection.getReceiverReport().getPackagesLostTotal() + ", "
					+ connection.getReceiverReport().getTimeFromLastSRRecv());
			}
		} else {
			System.out.println("Unknown session connection");
		}
		System.out.println();

	}

	@Override
	public void displayNodeItem(SessionNode node) {
		if(node != null) {
			System.out.println("SessionNode: " + node.getSsrc());
			System.out.println("\t" + node.getAddress().getHostAddress());
			System.out.println(node.getNodeType());
			if(node.getSenderInfo() != null) {
				System.out.println("\t\t Sender info: ");
				System.out.println("NTP: " +
						node.getSenderInfo().getNtp1TimeStamp() +
						", " + node.getSenderInfo().getNtp2TimeStamp());
				System.out.println("RTP: " + node.getSenderInfo().getRtpTimeStamp());
				System.out.println("Data sent: " + node.getSenderInfo().getTotalPackets() 
						+ ", " + node.getSenderInfo().getTotalOctets());
			}
			if(node.getNodeDescription() != null) {
				System.out.println(node.getNodeDescription().getCname() +
						" " + node.getNodeDescription().getEmail());
				System.out.println(node.getNodeDescription().getLoc() +
						" " + node.getNodeDescription().getName());
				System.out.println(node.getNodeDescription().getNote() +
						" " + node.getNodeDescription().getPhone());
				System.out.println(node.getNodeDescription().getPriv() +
						" " + node.getNodeDescription().getTool());
			}
			System.out.println();
		} else {
			System.out.println("Unknown session node");
		}

	}

}
